$(function(){
    // 控制ztree的状态,系统管理的ztree
    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };
    var zNodes =[
        { id:1, pId:0, name:"账号管理", open:true},
        { id:11, pId:1, name:"增", open:true},
        { id:12, pId:1, name:"删", open:true},
        { id:13, pId:1, name:"改", open:true},
        { id:14, pId:1, name:"查", open:true},

        { id:2, pId:0, name:"角色管理", open:true},
        { id:21, pId:2, name:"增"},
        { id:22, pId:2, name:"删"},
        { id:23, pId:2, name:"改"},
        { id:24, pId:2, name:"查"},

        { id:3, pId:0, name:"权限管理", open:true},
        { id:31, pId:3, name:"增"},
        { id:32, pId:3, name:"删"},
        { id:33, pId:3, name:"改"},
        { id:34, pId:3, name:"查"},

        { id:4, pId:0, name:"缓存管理", open:true},
        { id:41, pId:4, name:"刷新缓存"},

        { id:5, pId:0, name:"日志管理", open:true},
        { id:51, pId:5, name:"查看日志"},

    ];
    var code;
    function setCheck() {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
            py = $("#py").attr("checked")? "p":"",
            sy = $("#sy").attr("checked")? "s":"",
            pn = $("#pn").attr("checked")? "p":"",
            sn = $("#sn").attr("checked")? "s":"",
            type = { "Y":py + sy, "N":pn + sn};
        zTree.setting.check.chkboxType = type;
        showCode('setting.check.chkboxType = {  "Y" : "s", "N" : "ps"  };');
    }
    function showCode(str) {
        if (!code) code = $("#code");
        code.empty();
        code.append("<li>"+str+"</li>");
    }
    $(document).ready(function(){
        // 第一个ztree的
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        setCheck();
        $("#py").bind("change", setCheck);
        $("#sy").bind("change", setCheck);
        $("#pn").bind("change", setCheck);
        $("#sn").bind("change", setCheck);
    });

    // 第二个ztree的 后台管理的ztree
    var zNodesTwo =[
        { id:1, pId:0, name:"用户管理", open:true},
        { id:11, pId:1, name:"查看用户", open:true},

        { id:2, pId:0, name:"报告管理", open:true},
        { id:21, pId:2, name:"查看报告"},

        { id:3, pId:0, name:"资讯管理", open:true},
        { id:31, pId:3, name:"增"},
        { id:32, pId:3, name:"删"},
        { id:33, pId:3, name:"改"},
        { id:34, pId:3, name:"查"},
    ];

    function setCheckTwo() {
        var zTree = $.fn.zTree.getZTreeObj("ztreeHou"),
            py = $("#py").attr("checked")? "p":"",
            sy = $("#sy").attr("checked")? "s":"",
            pn = $("#pn").attr("checked")? "p":"",
            sn = $("#sn").attr("checked")? "s":"",
            type = { "Y":py + sy, "N":pn + sn};
        zTree.setting.check.chkboxType = type;
        showCodeTwo('setting.check.chkboxType = { "Y" : "s", "N" : "ps"  };');
    }
    // var ztCode;
    function showCodeTwo(str) {
        if (!code) code = $("#ztreeHou");
        code.empty();
        code.append("<li>"+str+"</li>");
    }
    $(document).ready(function(){
        $.fn.zTree.init($("#ztreeHou"), setting, zNodesTwo);
        setCheckTwo();
        $("#py").bind("change", setCheckTwo);
        $("#sy").bind("change", setCheckTwo);
        $("#pn").bind("change", setCheckTwo);
        $("#sn").bind("change", setCheckTwo);
    });



})